<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')

        this.chart.setOption({
          title: {
            text: '储罐罐顶类型统计图',
            textStyle: {
              color: '#3b7cbd'
            },
            x: '5%',
            y: '5%'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          legend: [
            {
              x: '65%',
              y: '30%',
              data: ['拱顶', '内浮顶'],
              inactiveColor: '#5e5e5e',
              textStyle: {
                color: '#ffffff'
              }
            },
            {
              x: '65%',
              y: '35%',
              data: ['内浮顶罐', '外浮顶'],
              inactiveColor: '#5e5e5e',
              textStyle: {
                color: '#ffffff'
              }
            },
            {
              x: '65%',
              y: '40%',
              data: ['拱顶罐', '浮顶罐'],
              inactiveColor: '#5e5e5e',
              textStyle: {
                color: '#ffffff'
              }
            },
            {
              x: '65%',
              y: '45%',
              data: ['立式圆筒形型'],
              inactiveColor: '#5e5e5e',
              textStyle: {
                color: '#ffffff'
              }
            },

          ],
          series: [
            {
              name: '储罐罐顶类型',
              type: 'pie',

              // radius: [15, 185],
              center: ['40%', '60%'],
              data: [
                {value: '6' ,name:   '内浮顶'},
                {value: '23', name:  '内浮顶罐'},
                {value: '8 ',name:   '外浮顶'},
                {value: '29',name:   '拱顶'},
                {value: '33',name:   '拱顶罐'},
                {value: '25',name:   '浮顶罐'},
                {value: '22',name:   '立式圆筒形型'}
                ],
            animationEasing: 'cubicInOut',
       animationDuration: 2600
            }
      ]
        })
      }
    }
  }
</script>
